
"""
老白读者的评分计算
"""
from models import Novel
from loguru import logger


class ReaderRating(object):

    def __init__(self):
        self.weights = {
            "情节设计": 0.3,
            "人物塑造": 0.3,
            "世界观构建": 0.2,
            "文笔写作": 0.2,
        }

        self.cn2en = {
            "情节设计": "plot_rating",
            "人物塑造": "character_rating",
            "世界观构建": "worldview_rating",
            "文笔写作": "style_rating",
        }

    def score(self, novel: Novel):
        """老白视角的评分计算"""
        total_score = 0
        for cn_key, weight in self.weights.items():
            en_key = self.cn2en[cn_key]
            score = getattr(novel, en_key).get("total_score")
            total_score += weight * float(score)
        novel.total_score = round(total_score)
        logger.info(f'总得分: {novel.total_score}')
